package com.wh.weibo.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Exception 拦截器，如果有饱错，则此处处理统一返回结果
 * @author WeiHong
 * @date 2019/7/8 19:23
 */
@ControllerAdvice
public class MyExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    @ResponseBody
    public Map doErrorMsg(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Exception ex){
        ex.printStackTrace();
        Map<String,Object> result = new HashMap<>(2);
        result.put("success",false);
        result.put("data","系统异常");
        return result;
    }
}
